package com.hzcc.wechatpayback.common;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author hzcc
 * @Date 2022/4/22
 *
 * 统一结果返回类
 */
@Data
@Accessors(chain = true)
public class ResultResponse {

    /**
     * 响应状态码
     */
    private int code;

    /**
     * 响应信息
     */
    private String message;

    /**
     * 响应数据
     */
    private Map<String, Object> data = new HashMap<>();

    /**
     * 默认返回（message，data）success
     * @param message
     * @return
     */
    public static ResultResponse defaultSuccessResultResponse(String message){
        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(200);
        resultResponse.setMessage(message);
        return resultResponse;
    }

    /**
     * 默认返回(无参)success
     * @return
     */
    public static ResultResponse defaultSuccessResultResponse(){
        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(200);
        resultResponse.setMessage("success");
        return resultResponse;
    }

    /**
     * 默认返回(无参)fail
     * @return
     */
    public static ResultResponse defaultFailResultResponse(){
        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(400);
        resultResponse.setMessage("fail");
        return resultResponse;
    }

    /**
     * 默认返回(message,data) fail
     * @param message
     * @return
     */
    public static ResultResponse defaultFailResultResponse(String message){
        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(400);
        resultResponse.setMessage(message);
        return resultResponse;
    }

    public ResultResponse data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

}
